<!DOCTYPE html>
<?php	$attempt = $_POST['getCompare'];   ?>
<h1>Results for attempt <?php echo $attempt ?></h1>
<?php 
require_once'functions.php';
require_once'config.php';
$studentID = $_SESSION['studentID'];
$selectedAttempt = $_POST['getCompare'];
$testID = 1;
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die ("Could not execute query");
$query = "SELECT * FROM studentresponse WHERE studentID ='$studentID' AND testID='$testID' AND attempt='$selectedAttempt' ORDER BY startTime ASC";
$result = mysqli_query($con,$query) or die ("Could not execute query");     
$nrows = mysqli_num_rows($result);
for ($i = 0; $i < $nrows; $i++ )
{	
	$row = mysqli_fetch_assoc($result);
	extract($row); 
{ 
$arrayAnswer = explode(",", $selectedAnswer);
sort($arrayAnswer);
$sorted = (implode(",", $arrayAnswer));
	if ($sorted == $correctAnswer)
				{ 
					$feedbackIcon = "<img class='feedbackIcon' src='img/checkmark.png' />";
					//echo "<img class='feedbackIcon' src='img/checkmark.png' />";
				} 
					else 
				{ 
					$feedbackIcon = "<img class='feedbackIcon' src='img/delete.png' />";

				//	echo "<img class='feedbackIcon' src='img/delete.png'/>";
				} 
 if (strlen($sorted) == strlen($correctAnswer))
{
	if (strpos($sorted, $correctAnswer) !== false)
 {
$arrayFeedbackStatus = "<span class='green'> Correct.</span>";
$feedbackIcon = "<img class='feedbackIcon' src='img/checkmark.png' />";
}
 }
else
{
$arrayFeedbackStatus = "<span class='red'> Incorrect.</span>";
$feedbackIcon = "<img class='feedbackIcon' src='img/delete.png' />";
 }
?>

<div class="fb">
<?php echo $feedbackIcon?>
<h2 class="reportItem">Question <?php echo $questionID?></h2>
<h2 class="reportItem"><?php ?></h2>
<p class="reportItem"><span class="emphasis">Selected Answer:</span> <?php echo $sorted; ?></p>
<p class="reportItem"><span class="emphasis">Correct Answer:</span> <?php echo $correctAnswer ?></p>  
<p class="reportItem"><span class="emphasis">Your answer was:</span> <?php echo $arrayFeedbackStatus ?></p>
<p class="reportItem"><span class="emphasis">Recommended resources:</span>Recommended resources for each question would be displayed here. Correct answers and incorrect answers would receive different recommonedations so that those who did not get the answer correct are not given resources that are based on knowledge they have been unable to demonstrate.</p> 
</div>  
 
  <?php }} 
$finalScore = finalScore($studentID, $attempt)?>
<h2>Final score:<?php echo $finalScore ?>/10</h2> 
<!--<h3>Achieved on <?php echo $startTime ?></h3>-->